﻿// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Pex.Graphs;
using Microsoft.ExtendedReflection.Utilities.Safe.Diagnostics;
using Microsoft.Pex.Engine.Comprehensions;
using Microsoft.Pex.Engine.ExecutionNodes;
using Microsoft.ExtendedReflection.Interpretation;
using Microsoft.ExtendedReflection.Reasoning.ExecutionNodes;
using Microsoft.ExtendedReflection.Utilities.Safe;
using Microsoft.Pex.Fitness.Interfaces;
using Microsoft.Pex.Engine.ComponentModel;

namespace Microsoft.Pex.Fitness.Implementation
{
    internal class PexFitnessSearchGraphBuilder :
        SearchGraphBuilder
    {
        readonly IPexFitnessExplorationManager fitnessManager;
        public PexFitnessSearchGraphBuilder(
            SearchGraphAttribute owner,
            IPexExplorationComponent host,
            IVisualExecutionGraph graph
            )
            : base(owner, host, graph)
        {
            this.fitnessManager = host.GetService<IPexFitnessExplorationManager>();
        }

        protected override string UpdateLabel(IExecutionNode node, string label)
        {
            string fitnessRep = this.fitnessManager.GetCompositeFitnessRepresentation(node);
            var result = SafeString.Format(
                @"{0}
fit: {1}", label, fitnessRep);

            return result;
        }
    }
}